﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using CRM.MODEL;
using CRM.UTIL;

namespace CRM.DAL
{
    public class PartsSuppliersD : DBChannel
    {
        /// <summary>
        /// 可以在此选择数据库连接，默认为CRM
        /// </summary>
        public PartsSuppliersD() : base()
        {
        }


        #region 执行存储过程 Pro_GetPartsSuppliers ,根据条件获取回馈信息

        /// <summary>
        /// 执行存储过程 Pro_GetPartsSuppliers 
        ///xialei
        /// </summary>

        public DataTable ExecuteGetPartsSuppliers(ref CRM.MODEL.GetPartsSuppliers stu)
        {
            //存储过程参数	 		     
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.IDPARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.SUPPLIERNAMEPARM, SqlDbType.VarChar,
                100));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.SUPPLIERCODEPARM, SqlDbType.VarChar,
                50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.TRADINGCERTIFICATENOPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.LEGALPERSONNAMEPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CORPORATEREPRESENTATIVEPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.REGISTEREDADDRESSPARM,
                SqlDbType.VarChar, 200));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CONTACTNAMEPARM, SqlDbType.VarChar,
                50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CONTACTPHONEPARM, SqlDbType.VarChar,
                50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.TELPHONEPARM, SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.QQPARM, SqlDbType.VarChar, 20));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.OFFICEADDRESSPARM, SqlDbType.VarChar,
                200));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.REMARKPARM, SqlDbType.VarChar, 200));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.ISAVAILABLEPARM, SqlDbType.Bit));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CREATEBYPARM, SqlDbType.VarChar, 20));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CREATETIMEPARM, SqlDbType.DateTime));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.LASTMODIFYBYPARM, SqlDbType.VarChar,
                20));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.LASTMODIFYTIMEPARM,
                SqlDbType.DateTime));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.KEYVALUEPARM,
                SqlDbType.VarChar));

            //分页参数
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.ORDERSTRING_PARM, SqlDbType.VarChar,
                1000));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.PAGESIZE_PARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.CURRENTPAGEINDEX_PARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.GetPartsSuppliers.TOTALITEMS_PARM, SqlDbType.Decimal));

            //设置参数的值
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.IDPARM].Value = stu.IDVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.SUPPLIERNAMEPARM].Value = stu.SUPPLIERNAMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.SUPPLIERCODEPARM].Value = stu.SUPPLIERCODEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.TRADINGCERTIFICATENOPARM].Value =
                stu.TRADINGCERTIFICATENOVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.LEGALPERSONNAMEPARM].Value = stu.LEGALPERSONNAMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CORPORATEREPRESENTATIVEPARM].Value =
                stu.CORPORATEREPRESENTATIVEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.REGISTEREDADDRESSPARM].Value = stu.REGISTEREDADDRESSVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CONTACTNAMEPARM].Value = stu.CONTACTNAMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CONTACTPHONEPARM].Value = stu.CONTACTPHONEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.TELPHONEPARM].Value = stu.TELPHONEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.QQPARM].Value = stu.QQVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.OFFICEADDRESSPARM].Value = stu.OFFICEADDRESSVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.REMARKPARM].Value = stu.REMARKVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.ISAVAILABLEPARM].Value = stu.ISAVAILABLEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CREATEBYPARM].Value = stu.CREATEBYVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CREATETIMEPARM].Value = stu.CREATETIMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.LASTMODIFYBYPARM].Value = stu.LASTMODIFYBYVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.LASTMODIFYTIMEPARM].Value = stu.LASTMODIFYTIMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.KEYVALUEPARM].Value = stu.KEYVALUEVALUE;

            //设置分页参数的值
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.ORDERSTRING_PARM].Value = stu.ORDERSTRING_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.PAGESIZE_PARM].Value = stu.PAGESIZE_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.CURRENTPAGEINDEX_PARM].Value = stu.CURRENTPAGEINDEX_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.TOTALITEMS_PARM].Value = stu.TOTALITEMS_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.TOTALITEMS_PARM].Direction = ParameterDirection.Output;

            //执行
            DataTable dt = this.GetDataByProcedure("dbo.Pro_GetPartsSuppliers");
            //获取数据库的信息
            stu.TOTALITEMS_VALUE = this.sqlCmd.Parameters[CRM.MODEL.GetPartsSuppliers.TOTALITEMS_PARM].Value;

            return dt;
        }

        #endregion

        #region 执行存储过程 Pro_EditPartsSuppliers,根据条件获取回馈信息

        /// <summary>
        /// 执行存储过程 Pro_EditPartsSuppliers 的相关参数
        ///xialei
        /// </summary>
        public int ExecuteEditPartsSuppliers(ref CRM.MODEL.EditPartsSuppliers stu)
        {
            if ((string) stu.ACTION_VALUE == "Update")
            {
                #region Update

                var sqlSb = new StringBuilder();
                sqlCmd.Parameters.Clear();
                sqlSb.Append(" UPDATE PartsSuppliers SET ");

                if (stu.ID_VALUE != DBNull.Value)
                {
                }
                if (stu.SUPPLIERNAME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierName=@SupplierName,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERNAME", stu.SUPPLIERNAME_VALUE));
                }
                if (stu.SUPPLIERCODE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierCode=@SupplierCode,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERCODE", stu.SUPPLIERCODE_VALUE));
                }
                if (stu.TRADINGCERTIFICATENO_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" TradingCertificateNO=@TradingCertificateNO,");
                    sqlCmd.Parameters.Add(new SqlParameter("@TRADINGCERTIFICATENO", stu.TRADINGCERTIFICATENO_VALUE));
                }
                if (stu.LEGALPERSONNAME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LegalPersonName=@LegalPersonName,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LEGALPERSONNAME", stu.LEGALPERSONNAME_VALUE));
                }
                if (stu.CORPORATEREPRESENTATIVE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" CorporateRepresentative=@CorporateRepresentative,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CORPORATEREPRESENTATIVE", stu.CORPORATEREPRESENTATIVE_VALUE));
                }
                if (stu.REGISTEREDADDRESS_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" RegisteredAddress=@RegisteredAddress,");
                    sqlCmd.Parameters.Add(new SqlParameter("@REGISTEREDADDRESS", stu.REGISTEREDADDRESS_VALUE));
                }
                if (stu.CONTACTNAME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" ContactName=@ContactName,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CONTACTNAME", stu.CONTACTNAME_VALUE));
                }
                if (stu.CONTACTPHONE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" ContactPhone=@ContactPhone,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CONTACTPHONE", stu.CONTACTPHONE_VALUE));
                }
                if (stu.TELPHONE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" TelPhone=@TelPhone,");
                    sqlCmd.Parameters.Add(new SqlParameter("@TELPHONE", stu.TELPHONE_VALUE));
                }
                if (stu.QQ_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" QQ=@QQ,");
                    sqlCmd.Parameters.Add(new SqlParameter("@QQ", stu.QQ_VALUE));
                }
                if (stu.OFFICEADDRESS_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" OfficeAddress=@OfficeAddress,");
                    sqlCmd.Parameters.Add(new SqlParameter("@OFFICEADDRESS", stu.OFFICEADDRESS_VALUE));
                }
                if (stu.REMARK_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" Remark=@Remark,");
                    sqlCmd.Parameters.Add(new SqlParameter("@REMARK", stu.REMARK_VALUE));
                }
                if (stu.ISAVAILABLE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" IsAvailable=@IsAvailable,");
                    sqlCmd.Parameters.Add(new SqlParameter("@ISAVAILABLE", stu.ISAVAILABLE_VALUE));
                }
                if (stu.CREATEBY_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" CreateBy=@CreateBy,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CREATEBY", stu.CREATEBY_VALUE));
                }
                if (stu.CREATETIME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" CreateTime=@CreateTime,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CREATETIME", stu.CREATETIME_VALUE));
                }
                if (stu.LASTMODIFYBY_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LastModifyBy=@LastModifyBy,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LASTMODIFYBY", stu.LASTMODIFYBY_VALUE));
                }
                if (stu.LASTMODIFYTIME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LastModifyTime=@LastModifyTime,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LASTMODIFYTIME", stu.LASTMODIFYTIME_VALUE));
                }

                var sql = sqlSb.ToString().TrimEnd(',');

                sqlCmd.Parameters.Add(new SqlParameter("@ID", stu.ID_VALUE));
                //sqlCmd.CommandText = sqlSb.ToString();
                //sqlCmd.ExecuteNonQuery();
                int i = base.ExecuteSQL(sql + " WHERE ID=@ID");

                return i;

                #endregion
            }
            else
            {
                //动作参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.ACTION_PARM, SqlDbType.VarChar,
                    20));
                //错误信息参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.ERRMSG_PARM, SqlDbType.VarChar,
                    100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.OUTID_PARM, SqlDbType.Int));
                ////表字段参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.IDPARM, SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.SUPPLIERNAMEPARM,
                    SqlDbType.VarChar, 100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.SUPPLIERCODEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.TRADINGCERTIFICATENOPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.LEGALPERSONNAMEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.CORPORATEREPRESENTATIVEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.REGISTEREDADDRESSPARM,
                    SqlDbType.VarChar, 200));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.CONTACTNAMEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.CONTACTPHONEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.TELPHONEPARM, SqlDbType.VarChar,
                    50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.QQPARM, SqlDbType.VarChar, 20));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.OFFICEADDRESSPARM,
                    SqlDbType.VarChar, 200));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.REMARKPARM, SqlDbType.VarChar,
                    200));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.ISAVAILABLEPARM, SqlDbType.Bit));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.CREATEBYPARM, SqlDbType.VarChar,
                    20));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.CREATETIMEPARM,
                    SqlDbType.DateTime));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.LASTMODIFYBYPARM,
                    SqlDbType.VarChar, 20));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.EditPartsSuppliers.LASTMODIFYTIMEPARM,
                    SqlDbType.DateTime));



                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.ACTION_PARM].Value = stu.ACTION_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.ERRMSG_PARM].Direction = ParameterDirection.Output;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.OUTID_PARM].Direction = ParameterDirection.Output;
                //设置参数的值
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.IDPARM].Value = stu.ID_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.SUPPLIERNAMEPARM].Value = stu.SUPPLIERNAME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.SUPPLIERCODEPARM].Value = stu.SUPPLIERCODE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.TRADINGCERTIFICATENOPARM].Value =
                    stu.TRADINGCERTIFICATENO_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.LEGALPERSONNAMEPARM].Value =
                    stu.LEGALPERSONNAME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.CORPORATEREPRESENTATIVEPARM].Value =
                    stu.CORPORATEREPRESENTATIVE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.REGISTEREDADDRESSPARM].Value =
                    stu.REGISTEREDADDRESS_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.CONTACTNAMEPARM].Value = stu.CONTACTNAME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.CONTACTPHONEPARM].Value = stu.CONTACTPHONE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.TELPHONEPARM].Value = stu.TELPHONE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.QQPARM].Value = stu.QQ_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.OFFICEADDRESSPARM].Value = stu.OFFICEADDRESS_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.REMARKPARM].Value = stu.REMARK_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.ISAVAILABLEPARM].Value = stu.ISAVAILABLE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.CREATEBYPARM].Value = stu.CREATEBY_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.CREATETIMEPARM].Value = stu.CREATETIME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.LASTMODIFYBYPARM].Value = stu.LASTMODIFYBY_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.LASTMODIFYTIMEPARM].Value = stu.LASTMODIFYTIME_VALUE;

                int i = this.ExecuteProcedure("dbo.Pro_EditPartsSuppliers"); //执行	
                //获取数据库的信息
                stu.ERRMSG_VALUE = this.sqlCmd.Parameters[CRM.MODEL.EditPartsSuppliers.ERRMSG_PARM].Value;
                return i;
            }
        }

        #endregion
    }
}